#
# 提升自尊模块
#


import datetime

from rasa_sdk.executor import CollectingDispatcher
from typing import Text, Dict, Any, List

from rasa_sdk import Action, Tracker
from rasa_sdk.events import SlotSet, SessionStarted, UserUtteranceReverted
from actions import common
import requests
import re
import time


def current_thought(tracker):
    num = tracker.get_slot('thought_3_change_1')
    cur = 'thought_' + str(num)
    text = tracker.get_slot(cur)
    return text


def conversation_rounds(tracker, **type):
    try:
        if common.rediscommon().get(tracker.current_state()['sender_id'] + '-wx-block-module2'):
            r = common.rediscommon()
            userid = tracker.current_state()['sender_id']
            r.set(userid + 'TempTimeSteame', str(time.time()), ex=86400)
            common.rediscommon().delete(tracker.current_state()['sender_id'] + '-wx-block-module2')
            return []
    except:
        pass
    if 'type' in type:
        if type['type'] == 1:
            userid = tracker.current_state()['sender_id']
            conn = common.POOL.connection(shareable=False)
            cursor = conn.cursor()
            cursor.execute(
                "Select * from `user_result` where topic_type=3 and is_end=0 and user_info_id ='" + userid + "' order by create_time desc")
            x = cursor.fetchone()
            sql = "update `user_result` set conversation_rounds=" + str(
                x[
                    15] + 1) + ",is_part_know=1 where `user_info_id` ='" + userid + "' and `is_end` = 0 and `topic_type` =3 order by create_time desc limit 1;"
            common.connectmysql(sql)
            return []

    userid = tracker.current_state()['sender_id']
    conn = common.POOL.connection(shareable=False)
    cursor = conn.cursor()
    cursor.execute(
        "Select * from `user_result` where topic_type=3 and is_end=0 and user_info_id ='" + userid + "' order by create_time desc")
    x = cursor.fetchone()
    if x[18] not in [(),None,]:
        r = common.rediscommon()
        try:
            temp = float(r.get(userid + 'TempTimeSteame'))
        except:
            temp = 0
        timenow = time.time()
        c = round(timenow - temp, 3)
        if x[18] == 0.001:
            sql = "update `user_result` set conversation_rounds=" + str(x[
                                                                            15] + 1) + ",response_time=" + str(
                c) + " where `user_info_id` ='" + userid + "' and `is_end` = 0 and `topic_type` =3 order by create_time desc limit 1;"
            common.connectmysql(sql)
        else:
            sql = "update `user_result` set conversation_rounds=" + str(x[
                                                                            15] + 1) + ",response_time=" + str(x[
                                                                                                                   18] + c) + " where `user_info_id` ='" + userid + "' and `is_end` = 0 and `topic_type` =3 order by create_time desc limit 1;"
            common.connectmysql(sql)
        r.set(userid + 'TempTimeSteame', str(time.time()), ex=86400)
    else:
        r = common.rediscommon()
        r.set(userid + 'TempTimeSteame', str(time.time()), ex=86400)
        sql = "update `user_result` set conversation_rounds=" + str(x[
                                                                        15] + 1) + ",response_time=0.000 where `user_info_id` ='" + userid + "' and `is_end` = 0 and `topic_type` =3 order by create_time desc limit 1;"
        common.connectmysql(sql)
    return []


class part5_1_1_choose_1(Action):
    def name(self) -> Text:
        return "action_part5_1_1_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        userid = tracker.current_state()['sender_id']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        try:
            cursor.execute(
                "Select * from `user_info` where `id` = '" + userid + "';")
            x = cursor.fetchone()
            nickname = x[1]
            names = x[2]
            if nickname is None:
                nickname = ''
            if names is None:
                names = ''
            test_batch = str(x[35])
            sql = "insert into `user_result`(`id`,`user_info_id`,`topic_type`,`name`,`conversation_rounds`,`nick_name`,`test_batch`) values('" + common.getuid() + "','" + userid + "',3,'" + names + "',0,'" + nickname + "',"+str(x[35])+");"
            common.connectmysql(sql)
            cursor.close()
            conn.close()
            conn = common.POOL.connection(shareable=False)
            cursor = conn.cursor()
            cursor.execute(
                "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
            x = cursor.fetchone()
            sql = "insert into `user_tools_response` (`id`,`user_info_id`,`user_result_id`,`name`,`use_tools`,`nick_name`,`test_batch`) values('" + common.getuid() + "','" + \
                  userid + "','" + x[0] + "','" + names + "','提升自尊','" + nickname + "',"+test_batch+");"
            common.connectmysql(sql)
        except:
            dispatcher.utter_message(text='机器人错误 错误码0x006')
            return [UserUtteranceReverted()]
        finally:
            cursor.close()
            conn.close()
        dispatcher.utter_message(text='我有这两个非常亲密的朋友，并且她们的友谊几乎是从出生就开始了。',
                                 buttons=[{'payload': '/button_part5_1_2_choose_1', 'title': '哦？', 'life': 1}, ],
                                 json_message={"module_type": 2,'word_module_type':4})
        conversation_rounds(tracker)
        return [SlotSet('self_esteem_slot_1', None), SlotSet('self_esteem_slot_2', None),
                SlotSet('self_esteem_slot_3', None), SlotSet('self_esteem_slot_4', None),
                SlotSet('self_esteem_slot_5', None), SlotSet('self_esteem_slot_6', None),
                SlotSet('self_esteem_slot_7', None), SlotSet('self_esteem_slot_8', None),
                SlotSet('self_esteem_slot_9', None), SlotSet('self_esteem_slot_10', None),
                SlotSet('self_esteem_slot_11', None), SlotSet('self_esteem_slot_12', None),
                SlotSet('self_esteem_slot_13', None), SlotSet('self_esteem_slot_14', None),
                SlotSet('self_esteem_slot_15', None), ]


class part5_1_2_choose_1(Action):
    def name(self) -> Text:
        return "action_part5_1_2_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='对呀，她们就像豆荚里的两颗豌豆。 他们一起上学，在同一个社区长大，有很多相同的朋友。',
                                 buttons=[{'payload': '/button_part5_1_3_choose_1', 'title': '哇哦～', 'life': 1}, ])
        return []


class part5_1_3_choose_1(Action):
    def name(self) -> Text:
        return "action_part5_1_3_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='但是她们之间有一个重要的区别...',
                                 buttons=[{'payload': '/button_part5_1_4_choose_1', 'title': '什么区别？？', 'life': 1}, ])
        return []


class part5_1_4_choose_1(Action):
    def name(self) -> Text:
        return "action_part5_1_4_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='她们的自尊心...',
                                 buttons=[{'payload': '/button_part5_1_5_choose_1', 'title': '嗯？？？', 'life': 1}, ])
        return []


class part5_1_5_choose_1(Action):
    def name(self) -> Text:
        return "action_part5_1_5_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='自尊就是我们如何看待自己。我们都会有不同的自尊水平，同时对我们自己的看法也不尽相同。',
                                 buttons=[{'payload': '/button_part5_1_6_choose_1', 'title': '嗯嗯', 'life': 1}, ])
        return []


class part5_1_6_choose_1(Action):
    def name(self) -> Text:
        return "action_part5_1_6_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='首先，我的朋友佑佑。 她有一份不错的工作，成绩一般，生活相对简单。',
                                 buttons=[{'payload': '/button_part5_1_7_choose_1', 'title': 'Okay', 'life': 1}, ])
        return []


class part5_1_7_choose_1(Action):
    def name(self) -> Text:
        return "action_part5_1_7_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='小迪有一份非常有声望的工作，在大学里一直是班上的佼佼者，并且家境也非常优越......',
                                 buttons=[{'payload': '/button_part5_1_8_choose_1', 'title': '哇哦~', 'life': 1}, ])
        return []


class part5_1_8_choose_1(Action):
    def name(self) -> Text:
        return "action_part5_1_8_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='是的，但有趣的是，佑佑是一个自尊心很强的人。 她对自己有一个积极的态度和判断，不受外部成就指标的影响',
                                 buttons=[{'payload': '/button_part5_1_9_choose_1', 'title': '那小迪呢', 'life': 1}, ])
        return []


class part5_1_9_choose_1(Action):
    def name(self) -> Text:
        return "action_part5_1_9_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='小迪有非常低的自尊心。她从不觉得自己足够好，她自我批评，从来不对自己感到满意，害怕在任何层面上犯错。',
                                 buttons=[{'payload': '/button_part5_1_10_choose_1', 'title': '所以呢？', 'life': 1}, ])
        return []


class part5_1_10_choose_1(Action):
    def name(self) -> Text:
        return "action_part5_1_10_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='由此看来，是否喜欢自己似乎不仅仅取决于外部的认可，它更多地与我们告诉自己的事情有关，进而与我们的行为有关。',
                                 buttons=[{'payload': '/button_part5_1_11_choose_1', 'title': '真的吗？', 'life': 1}, ])
        return []


class part5_1_11_choose_1(Action):
    def name(self) -> Text:
        return "action_part5_1_11_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='是的！拥有良好的自尊并不是要达到某个特定的基准。 相反，它似乎与我们内部的声音和主观思维有关。',
                                 buttons=[{'payload': '/button_part5_1_12_choose_1', 'title': '有道理……', 'life': 1}, ])
        return []


class part5_1_12_choose_1(Action):
    def name(self) -> Text:
        return "action_part5_1_12_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='但这其实是一个好消息，因为我们可以学会与内心的批判者作斗争，并且挑战我们自己的想法。',
                                 buttons=[{'payload': '/button_part5_1_13_choose_1', 'title': '怎么做呢？', 'life': 1}, ])
        return []


class part5_1_13_choose_1(Action):
    def name(self) -> Text:
        return "action_part5_1_13_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='你是否曾经觉得自己的自尊心很低？',
                                 buttons=[{'payload': '/button_part5_1_14_choose_1', 'title': '是', 'life': 1},
                                          {'payload': '/button_part5_1_14_choose_1', 'title': '有时候', 'life': 1},
                                          {'payload': '/button_part5_1_14_choose_2', 'title': '没有', 'life': 1}, ])
        return []


class part5_1_14_choose_1(Action):
    def name(self) -> Text:
        return "action_part5_1_14_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='我可以确切地告诉你我是如何帮助小迪的，你想听听吗？',image='https://obs-e912.obs.cn-east-2.myhuaweicloud.com/zy_xm/image/rasa_photo_2021_08_16/add/cute_cat.png',
                                 buttons=[{'payload': '/button_part5_1_15_choose_1', 'title': '想', 'life': 1},
                                          {'payload': '/button_part5_1_15_choose_2', 'title': '不想', 'life': 1},
                                          {'payload': '/button_part5_1_15_choose_2', 'title': '下次吧', 'life': 1}, ])
        return []


class part5_1_14_choose_2(Action):
    def name(self) -> Text:
        return "action_part5_1_14_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='真好！我真为你感到高兴，你想了解我是如何帮助我的人类朋友小迪的吗？ ',image='https://obs-e912.obs.cn-east-2.myhuaweicloud.com/zy_xm/image/rasa_photo_2021_08_16/add/cute_cat.png',
                                 buttons=[{'payload': '/button_part5_1_15_choose_1', 'title': '想', 'life': 1},
                                          {'payload': '/button_part5_1_15_choose_2', 'title': '不想', 'life': 1},
                                          {'payload': '/button_part5_1_15_choose_2', 'title': '下次吧', 'life': 1}, ])
        return []


class part5_1_15_choose_1(Action):
    def name(self) -> Text:
        return "action_part5_1_15_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='好耶！所以小迪意识到的第一件事就是，她总是将自己与同龄人进行比较，这样子并不健康。',
                                 buttons=[{'payload': '/button_part5_1_16_choose_1', 'title': '哦？', 'life': 1}, ])
        return []


class part5_1_15_choose_2(Action):
    def name(self) -> Text:
        return "action_part5_1_15_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        sql = "update `user_result` set `is_end` = 1,end_time=now() where `user_info_id`='" + userid + "' and `topic_type` = 3 and `is_end` = 0 order by create_time desc limit 1;"
        common.connectmysql(sql)
        dispatcher.utter_message(text='你已完成当天的实验流程')
        dispatcher.utter_message(text='那我们下次再聊，拜拜哦', buttons=[
            {'payload': '/greet', 'title': '拜拜~', 'life': 1}])
        return []


class part5_1_16_choose_1(Action):
    def name(self) -> Text:
        return "action_part5_1_16_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='相对于人口中的“每个人”，她并不觉得自己不够格。 但是相比于那些与她受过同样教育，年龄相近，来自相似的地区的其他人……',
                                 buttons=[{'payload': '/button_part5_1_17_choose_1', 'title': '哦？', 'life': 1}, ])
        return []


class part5_1_17_choose_1(Action):
    def name(self) -> Text:
        return "action_part5_1_17_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='那些人的成就和成功对她来说比什么都重要。',
                                 buttons=[{'payload': '/button_part5_1_18_choose_1', 'title': '我明白了……', 'life': 1}, ])
        return []


class part5_1_18_choose_1(Action):
    def name(self) -> Text:
        return "action_part5_1_18_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='这意味着，当她的一个朋友开始自己的事业或者另一个朋友出版了一本书时，她便会感到沮丧和自卑。',
                                 buttons=[{'payload': '/button_part5_1_19_choose_1', 'title': '天呐……', 'life': 1}, ])
        return []


class part5_1_19_choose_1(Action):
    def name(self) -> Text:
        return "action_part5_1_19_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='但是，当小迪意识到她所进行的比较对自己是有害的并且也并不公平时，她可以开始改变自己的想法。',
                                 buttons=[{'payload': '/button_part6_1_1_choose_1', 'title': '太好了', 'life': 1}, ])
        return []


# -----------------------------------------------part6-----------------------------------------------
class part6_1_1_choose_1(Action):
    def name(self) -> Text:
        return "action_part6_1_1_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='她意识到她唯一真正的竞争对手其实是自己……所以她决定问四个问题。 你想试一下吗？',image='https://obs-e912.obs.cn-east-2.myhuaweicloud.com/zy_xm/image/rasa_photo_2021_08_16/add/try.png',
                                 buttons=[{'payload': '/actives_self_esteem_form1', 'title': '好呀', 'life': 1},
                                          {'payload': '/button_part6_1_2_choose_1', 'title': '不', 'life': 1}, ])
        return []


class part6_1_2_choose_1(Action):
    def name(self) -> Text:
        return "action_part6_1_2_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='没关系，你想继续小迪故事的下一章吗？',
                                 buttons=[{'payload': '/button_part6_1_3_choose_1', 'title': '想', 'life': 1},
                                          {'payload': '/button_part6_1_3_choose_2', 'title': '不想', 'life': 1}, ])
        return []


class part6_1_3_choose_1(Action):
    def name(self) -> Text:
        return "action_part6_1_3_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='小迪在提高自尊的道路上迈出的第一步是写一份她喜欢自己的事情的清单。',
                                 buttons=[{'payload': '/button_part6_1_4_choose_1', 'title': '比如呢？', 'life': 1},
                                          {'payload': '/button_part6_1_4_choose_2', 'title': '你的清单是什么？', 'life': 1}, ])
        return []


class part6_1_3_choose_2(Action):
    def name(self) -> Text:
        return "action_part6_1_3_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        sql = "update `user_result` set `is_end` = 1,end_time=now() where `user_info_id`='" + userid + "' and `topic_type` = 3 and `is_end` = 0 order by create_time desc limit 1;"
        common.connectmysql(sql)
        dispatcher.utter_message(text='你已完成当天的实验流程')
        dispatcher.utter_message(text='好吧，拜拜~', buttons=[
            {'payload': '/greet', 'title': '拜拜~', 'life': 1}])
        return []


class part6_1_4_choose_1(Action):
    def name(self) -> Text:
        return "action_part6_1_4_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='比如说你一直是一个很好的倾听者，或者你很擅长打羽毛球，又或者你写了一封深思熟虑的信给你的家人。',image='https://obs-e912.obs.cn-east-2.myhuaweicloud.com/zy_xm/image/rasa_photo_2021_08_16/add/pride.png',
                                 buttons=[{'payload': '/button_part6_1_5_choose_1', 'title': '哦~', 'life': 1}, ])
        return []


class part6_1_4_choose_2(Action):
    def name(self) -> Text:
        return "action_part6_1_4_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='我是一个很棒的舞者，一个很好的聊天机器人，我的心（或至少我的编程）是善良的。',image='https://obs-e912.obs.cn-east-2.myhuaweicloud.com/zy_xm/image/rasa_photo_2021_08_16/add/pride.png',
                                 buttons=[{'payload': '/button_part6_1_5_choose_1', 'title': '哇哦~', 'life': 1}, ])
        return []


class part6_1_5_choose_1(Action):
    def name(self) -> Text:
        return "action_part6_1_5_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='当你失去信心，而且无法思考其他任何事情的时候，它会是一个有用的清单。',
                                 buttons=[{'payload': '/actives_self_esteem_form3', 'title': '好贴心呀', 'life': 1}])
        return []

    class action_ask_self_esteem_slot_1(Action):
        def name(self) -> Text:
            return "action_ask_self_esteem_slot_1"

        async def run(
                self,
                dispatcher: CollectingDispatcher,
                tracker: Tracker,
                domain: Dict[Text, Any],
        ) -> List[Dict[Text, Any]]:
            conversation_rounds(tracker)
            dispatcher.utter_message(text="好耶！所以现在你如何看待自己呢？写在下面。✏️写在下面的输入框中让小E更懂你，不要点击任何选项哦。")
            return []


class action_ask_self_esteem_slot_2(Action):
    def name(self) -> Text:
        return "action_ask_self_esteem_slot_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        try:
            cursor.execute(
                "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
            x = cursor.fetchone()
            result_id = x[0]
            sql = "update `user_tools_response` set self_esteem_think_of_yourself='" + tracker.get_slot(
                'self_esteem_slot_1') + "' where `user_info_id` ='" + userid + "' and `user_result_id` = '" + result_id + "' limit 1;"
            common.connectmysql(sql)
        except:
            dispatcher.utter_message(text='机器人错误 错误码0x020')
            return [UserUtteranceReverted()]
        finally:
            cursor.close()
            conn.close()
        dispatcher.utter_message(text="你想成为什么样的人？ 写在下面。 ✏️")
        return []


class action_ask_self_esteem_slot_3(Action):
    def name(self) -> Text:
        return "action_ask_self_esteem_slot_3"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="有没有更友好、更有益的思考自己的方式？🤔写在下面✏️ ")
        return []


class action_ask_self_esteem_slot_4(Action):
    def name(self) -> Text:
        return "action_ask_self_esteem_slot_4"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        try:
            cursor.execute(
                "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
            x = cursor.fetchone()
            result_id = x[0]
            sql = "update `user_tools_response` set self_esteem_think_kinder='" + tracker.get_slot('self_esteem_slot_3') + "' where `user_info_id` ='" + userid + "' and `user_result_id` = '" + result_id + "' limit 1;"
            common.connectmysql(sql)
        except:
            dispatcher.utter_message(text='机器人错误 错误码0x020')
            return [UserUtteranceReverted()]
        finally:
            cursor.close()
            conn.close()
        dispatcher.utter_message(text="你觉得别人如何看待你呢？写在下面✏️")
        return []


class action_ask_self_esteem_slot_5(Action):
    def name(self) -> Text:
        return "action_ask_self_esteem_slot_5"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        try:
            cursor.execute(
                "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
            x = cursor.fetchone()
            result_id = x[0]
            sql = "update `user_tools_response` set self_esteem_others_think='" + tracker.get_slot('self_esteem_slot_4') + "' where `user_info_id` ='" + userid + "' and `user_result_id` = '" + result_id + "' limit 1;"
            common.connectmysql(sql)
        except:
            dispatcher.utter_message(text='机器人错误 错误码0x020')
            return [UserUtteranceReverted()]
        finally:
            cursor.close()
            conn.close()
        dispatcher.utter_message(text="你希望别人怎样看待你呢？写在下面✏️")
        return []


class action_ask_self_esteem_slot_6(Action):
    def name(self) -> Text:
        return "action_ask_self_esteem_slot_6"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        try:
            cursor.execute(
                "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
            x = cursor.fetchone()
            result_id = x[0]
            sql = "update `user_tools_response` set self_esteem_wish_others_think='" + tracker.get_slot('self_esteem_slot_5') + "' where `user_info_id` ='" + userid + "' and `user_result_id` = '" + result_id + "' limit 1;"
            common.connectmysql(sql)
        except:
            dispatcher.utter_message(text='机器人错误 错误码0x020')
            return [UserUtteranceReverted()]
        finally:
            cursor.close()
            conn.close()
        dispatcher.utter_message(text="你认为这些想法是完全可以实现的，还是介于两者之间的合理范围？ 有没有你无法控制的因素？ 在下面写下可能的限制。 ✏️")
        return []


class action_ask_self_esteem_slot_7(Action):
    def name(self) -> Text:
        return "action_ask_self_esteem_slot_7"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="那么首先，你在生活中做了什么让你感到高兴的事？ 写在下面。✏️")
        return []


class action_ask_self_esteem_slot_8(Action):
    def name(self) -> Text:
        return "action_ask_self_esteem_slot_8"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        try:
            cursor.execute(
                "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
            x = cursor.fetchone()
            result_id = x[0]
            sql = "update `user_tools_response` set self_esteem_happy_thing='" + tracker.get_slot('self_esteem_slot_7') + "' where `user_info_id` ='" + userid + "' and `user_result_id` = '" + result_id + "' limit 1;"
            common.connectmysql(sql)
        except:
            dispatcher.utter_message(text='机器人错误 错误码0x020')
            return [UserUtteranceReverted()]
        finally:
            cursor.close()
            conn.close()
        dispatcher.utter_message(text="你遇到过哪些挑战，它告诉了你些什么？ 写在下面。 ✏️")
        return []


class action_ask_self_esteem_slot_9(Action):
    def name(self) -> Text:
        return "action_ask_self_esteem_slot_9"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="好吧，想想在对自己感到沮丧时，你当时在做什么？ 写在下面。  ✏️")
        return []


class action_ask_self_esteem_slot_10(Action):
    def name(self) -> Text:
        return "action_ask_self_esteem_slot_10"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        try:
            cursor.execute(
                "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
            x = cursor.fetchone()
            result_id = x[0]
            sql = "update `user_tools_response` set self_esteem_fell_down_thing='" + tracker.get_slot('self_esteem_slot_9') + "' where `user_info_id` ='" + userid + "' and `user_result_id` = '" + result_id + "' limit 1;"
            common.connectmysql(sql)
        except:
            dispatcher.utter_message(text='机器人错误 错误码0x020')
            return [UserUtteranceReverted()]
        finally:
            cursor.close()
            conn.close()
        dispatcher.utter_message(text="这个时候你在想什么？ 写在下面。  ✏️")
        return []


class action_ask_self_esteem_slot_11(Action):
    def name(self) -> Text:
        return "action_ask_self_esteem_slot_11"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        try:
            cursor.execute(
                "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
            x = cursor.fetchone()
            result_id = x[0]
            sql = "update `user_tools_response` set self_esteem_fell_down_think='" + tracker.get_slot('self_esteem_slot_10') + "' where `user_info_id` ='" + userid + "' and `user_result_id` = '" + result_id + "' limit 1;"
            common.connectmysql(sql)
        except:
            dispatcher.utter_message(text='机器人错误 错误码0x020')
            return [UserUtteranceReverted()]
        finally:
            cursor.close()
            conn.close()
        dispatcher.utter_message(text="结果发生了什么？ 写在下面。  ✏ ")
        return []


class action_ask_self_esteem_slot_12(Action):
    def name(self) -> Text:
        return "action_ask_self_esteem_slot_12"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="比如你的想法是真的吗？ 写在下面。")
        return []


class action_ask_self_esteem_slot_13(Action):
    def name(self) -> Text:
        return "action_ask_self_esteem_slot_13"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        try:
            cursor.execute(
                "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
            x = cursor.fetchone()
            result_id = x[0]
            sql = "update `user_tools_response` set self_esteem_thought_true='" + tracker.get_slot('self_esteem_slot_12') + "' where `user_info_id` ='" + userid + "' and `user_result_id` = '" + result_id + "' limit 1;"
            common.connectmysql(sql)
        except:
            dispatcher.utter_message(text='机器人错误 错误码0x020')
            return [UserUtteranceReverted()]
        finally:
            cursor.close()
            conn.close()
        dispatcher.utter_message(text="你的想法中哪些部分是虚假的、错误的？ ✏️")
        return []


class action_ask_self_esteem_slot_14(Action):
    def name(self) -> Text:
        return "action_ask_self_esteem_slot_14"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        try:
            cursor.execute(
                "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
            x = cursor.fetchone()
            result_id = x[0]
            sql = "update `user_tools_response` set self_esteem_thought_false_part='" + tracker.get_slot('self_esteem_slot_13') + "' where `user_info_id` ='" + userid + "' and `user_result_id` = '" + result_id + "' limit 1;"
            common.connectmysql(sql)
        except:
            dispatcher.utter_message(text='机器人错误 错误码0x020')
            return [UserUtteranceReverted()]
        finally:
            cursor.close()
            conn.close()
        dispatcher.utter_message(text="你会对抱有这些想法的朋友说些什么？ 写在下面。  ✏ ")
        return []


class action_ask_self_esteem_slot_15(Action):
    def name(self) -> Text:
        return "action_ask_self_esteem_slot_15"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        try:
            cursor.execute(
                "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
            x = cursor.fetchone()
            result_id = x[0]
            sql = "update `user_tools_response` set self_esteem_say_to_friend='" + tracker.get_slot(
                'self_esteem_slot_14') + "' where `user_info_id` ='" + userid + "' and `user_result_id` = '" + result_id + "' limit 1;"
            common.connectmysql(sql)
        except:
            dispatcher.utter_message(text='机器人错误 错误码0x020')
            return [UserUtteranceReverted()]
        finally:
            cursor.close()
            conn.close()
        dispatcher.utter_message(text="现在想想哪种想法更加合理。 实际上可能发生的最坏情况是什么？ 写在下面。  ✏ ")
        return []

    class action_self_esteem_save_1(Action):
        def name(self) -> Text:
            return "action_self_esteem_save_1"

        async def run(
                self,
                dispatcher: CollectingDispatcher,
                tracker: Tracker,
                domain: Dict[Text, Any],
        ) -> List[Dict[Text, Any]]:
            conversation_rounds(tracker)
            userid = tracker.current_state()['sender_id']
            conn = common.POOL.connection(shareable=False)
            cursor = conn.cursor()
            try:
                cursor.execute(
                    "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
                x = cursor.fetchone()
                result_id = x[0]
                sql = "update `user_tools_response` set self_esteem_want_to_be='" + tracker.get_slot('self_esteem_slot_2') + "' where `user_info_id` ='" + userid + "' and `user_result_id` = '" + result_id + "' limit 1;"
                common.connectmysql(sql)
            except:
                dispatcher.utter_message(text='机器人错误 错误码0x020')
                return [UserUtteranceReverted()]
            finally:
                cursor.close()
                conn.close()
            dispatcher.utter_message(text="想想这些想法是否现实，或者这个目标是否在为失败而设...",
                                     buttons=[{'payload': '/actives_self_esteem_form2', 'title': '好的', 'life': 1}])
            return []


class action_self_esteem_save_2(Action):
    def name(self) -> Text:
        return "action_self_esteem_save_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        try:
            cursor.execute(
                "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
            x = cursor.fetchone()
            result_id = x[0]
            sql = "update `user_tools_response` set self_esteem_factors='" + tracker.get_slot('self_esteem_slot_6') + "' where `user_info_id` ='" + userid + "' and `user_result_id` = '" + result_id + "' limit 1;"
            common.connectmysql(sql)
        except:
            dispatcher.utter_message(text='机器人错误 错误码0x020')
            return [UserUtteranceReverted()]
        finally:
            cursor.close()
            conn.close()
        dispatcher.utter_message(text="她意识到，如果她的自尊只依赖于外部条件，她可能会过度努力来给她遇到的每个人留下深刻印象。 而这可能会成为一场持续的完美主义竞赛。",
                                 buttons=[{'payload': '/button_part6_1_3_choose_1', 'title': '是呢', 'life': 1}])
        return []


class action_self_esteem_save_3(Action):
    def name(self) -> Text:
        return "action_self_esteem_save_3"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        try:
            cursor.execute(
                "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
            x = cursor.fetchone()
            result_id = x[0]
            sql = "update `user_tools_response` set self_esteem_challenge='" + tracker.get_slot('self_esteem_slot_8') + "' where `user_info_id` ='" + userid + "' and `user_result_id` = '" + result_id + "' limit 1;"
            common.connectmysql(sql)
        except:
            dispatcher.utter_message(text='机器人错误 错误码0x020')
            return [UserUtteranceReverted()]
        finally:
            cursor.close()
            conn.close()
        dispatcher.utter_message(text="干得漂亮。如果你也曾经被这类问题所困扰，没关系，你可以问问你的朋友们他们喜欢你哪里。这就是小迪所做的事情，朋友们给出的回复让她很惊喜。 😝",image='https://obs-e912.obs.cn-east-2.myhuaweicloud.com/zy_xm/image/rasa_photo_2021_08_16/add/cute_pig.png',
                                 buttons=[{'payload': '/actives_self_esteem_form4', 'title': '好主意呀', 'life': 1}])
        return []


class action_self_esteem_save_4(Action):
    def name(self) -> Text:
        return "action_self_esteem_save_4"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        try:
            cursor.execute(
                "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
            x = cursor.fetchone()
            result_id = x[0]
            sql = "update `user_tools_response` set self_esteem_fell_down_result='" + tracker.get_slot('self_esteem_slot_11') + "' where `user_info_id` ='" + userid + "' and `user_result_id` = '" + result_id + "' limit 1;"
            common.connectmysql(sql)
        except:
            dispatcher.utter_message(text='机器人错误 错误码0x020')
            return [UserUtteranceReverted()]
        finally:
            cursor.close()
            conn.close()
        dispatcher.utter_message(text="干得好。 现在，当你内心的批评者活跃时，你的想法通常是准确的想法和错误的扭曲想法的混合体。 你可以问自己一些问题来弄清楚。",
                                 buttons=[{'payload': '/actives_self_esteem_form5', 'title': '比如呢？', 'life': 1}])
        return []


class action_self_esteem_save_5(Action):
    def name(self) -> Text:
        return "action_self_esteem_save_5"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        try:
            cursor.execute(
                "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
            x = cursor.fetchone()
            result_id = x[0]
            sql = "update `user_tools_response` set self_esteem_worst_could_happen='" + tracker.get_slot('self_esteem_slot_15') + "' where `user_info_id` ='" + userid + "' and `user_result_id` = '" + result_id + "' limit 1;"
            common.connectmysql(sql)
        except:
            dispatcher.utter_message(text='机器人错误 错误码0x020')
            return [UserUtteranceReverted()]
        finally:
            cursor.close()
            conn.close()
        dispatcher.utter_message(text="小迪反复这样做，并且发现这是让她内心的批评者保持沉默的好方法。 有时她仍然会很挣扎。但当她需要的时候，她就会回到这里进行练习。",
                                 buttons=[{'payload': '/button_part7_1_1_choose_1', 'title': '小迪好棒啊', 'life': 1}])
        return []


class part7_1_1_choose_1(Action):
    def name(self) -> Text:
        return "action_part7_1_1_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='是呀，你也很棒！我们马上就要走到终点啦',
                                 buttons=[{'payload': '/button_part7_1_2_choose_1', 'title': '嗯嗯🏁', 'life': 1}, ])
        return []


class part7_1_2_choose_1(Action):
    def name(self) -> Text:
        return "action_part7_1_2_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='小迪还注意到，当她的自尊心很低时，她倾向于避免做她认为自己不擅长的事情。',image='https://obs-e912.obs.cn-east-2.myhuaweicloud.com/zy_xm/image/rasa_photo_2021_08_16/add/cant_do.png',
                                 buttons=[{'payload': '/button_part7_1_3_choose_1', 'title': '真的吗？', 'life': 1},
                                          {'payload': '/button_part7_1_3_choose_2', 'title': '比如呢？', 'life': 1}, ])
        return []


class part7_1_3_choose_1(Action):
    def name(self) -> Text:
        return "action_part7_1_3_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='是的，因此不可避免地，她无法了解到关于自己的任何新东西。 她本可以成为一个优秀的霹雳舞者。但是如果她不尝试，她永远也不会知道！',
                                 buttons=[{'payload': '/button_part7_1_4_choose_1', 'title': '哦……', 'life': 1}, ])
        return []


class part7_1_3_choose_2(Action):
    def name(self) -> Text:
        return "action_part7_1_3_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='它可以是任何东西！攀岩、溜冰、卡拉OK……或者其他像外出和社交之类的活动。',
                                 buttons=[{'payload': '/button_part7_1_4_choose_1', 'title': '啊～我懂了', 'life': 1}, ])
        return []


class part7_1_4_choose_1(Action):
    def name(self) -> Text:
        return "action_part7_1_4_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='所以她决定制作另一份清单',
                                 buttons=[{'payload': '/button_part7_1_5_choose_1', 'title': '关于什么呢？', 'life': 1}, ])
        return []


class part7_1_5_choose_1(Action):
    def name(self) -> Text:
        return "action_part7_1_5_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='那些由于她的自卑没能做成的事情，以及她希望以更高的自尊实现的目标……',
                                 buttons=[{'payload': '/button_part7_1_6_choose_1', 'title': '然后呢？', 'life': 1}, ])
        return []


class part7_1_6_choose_1(Action):
    def name(self) -> Text:
        return "action_part7_1_6_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='这帮助她看到了相信自己但又不过度期望完美的好处。',
                                 buttons=[{'payload': '/button_part7_1_7_choose_1', 'title': '哇哦😝', 'life': 1}, ])
        return []


class part7_1_7_choose_1(Action):
    def name(self) -> Text:
        return "action_part7_1_7_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='她还与我分享了一个神秘技巧，她喜欢称之为“快速修复”',
                                 buttons=[{'payload': '/button_part7_1_8_choose_1', 'title': '那是什么？', 'life': 1}, ])
        return []


class part7_1_8_choose_1(Action):
    def name(self) -> Text:
        return "action_part7_1_8_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='她使用积极的“自我对话”作为一个小小的助推器。 例如“我明白了”之类的短语。 “我做过一次，我可以再做一次”“冲啊”',image='https://obs-e912.obs.cn-east-2.myhuaweicloud.com/zy_xm/image/rasa_photo_2021_08_16/add/can_do.png',
                                 buttons=[{'payload': '/button_part7_1_9_choose_1', 'title': '哦~好棒呀', 'life': 1}, ])
        return []


class part7_1_9_choose_1(Action):
    def name(self) -> Text:
        return "action_part7_1_9_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='你觉得今天的课程怎么样呢？',
                                 buttons=[{'payload': '/button_part7_1_10_choose_1', 'title': '好👍', 'life': 1},
                                          {'payload': '/button_part7_1_10_choose_1_2', 'title': '不好👎', 'life': 1}, ])
        return []


class part7_1_10_choose_1(Action):
    def name(self) -> Text:
        return "action_part7_1_10_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        try:
            cursor.execute(
                "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
            x = cursor.fetchone()
            result_id = x[0]
            if tracker.current_state()['events'][-2]['text'] == '/button_part7_1_10_choose_1':
                sqlchange = "update user_tools_response set evaluation_self_esteem='好' where `user_info_id` ='" + userid + "' and `user_result_id` = '" + result_id + "' limit 1;"
            if tracker.current_state()['events'][-2]['text'] == '/button_part7_1_10_choose_1_2':
                sqlchange = "update user_tools_response set evaluation_self_esteem='不好' where `user_info_id` ='" + userid + "' and `user_result_id` = '" + result_id + "' limit 1;"
            common.connectmysql(sqlchange)
        except:
            dispatcher.utter_message(text='机器人错误 错误码0x050')
            return [UserUtteranceReverted()]
        finally:
            cursor.close()
            conn.close()
        sql = "update `user_result` set `is_end` = 1,end_time=now() where `user_info_id`='" + userid + "' and `topic_type` = 3 and `is_end` = 0 order by create_time desc limit 1;"
        common.connectmysql(sql)
        dispatcher.utter_message(text='你已完成当天的实验流程')
        dispatcher.utter_message(text='那就好。祝你好运哦，我们之后再聊，拜拜ヾ(•ω•`)o', buttons=[
            {'payload': '/greet', 'title': '拜拜~', 'life': 1}])
        return []


class part7_1_10_choose_2(Action):
    def name(self) -> Text:
        return "action_part7_1_10_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        sql = "update `user_result` set `is_end` = 1,end_time=now() where `user_info_id`='" + userid + "' and `topic_type` = 3 and `is_end` = 0 order by create_time desc limit 1;"
        common.connectmysql(sql)
        dispatcher.utter_message(text='你已完成当天的实验流程')
        dispatcher.utter_message(text='好吧，我很遗憾没有帮助到你，也许将来我们会找到一些对你更有帮助的方法。我们之后再聊，拜拜哦。', buttons=[
            {'payload': '/greet', 'title': '拜拜~', 'life': 1}])
        return []
